// 上传图片并预览
var inputpic = document.getElementById("inputfile")
inputpic.onchange = function () {
    var file = this.files[0]
    var imageUrl = URL.createObjectURL(file);
    document.getElementById("willsetImg").src = imageUrl;
    document.getElementById("willsetImg").style = "width:200px,height:200px";
}

let mottoResult = document.getElementById("authormotto").value
let arr = [mottoResult.split(",")][0]
let motto = document.getElementsByTagName("textarea")[0]
motto.innerText = arr

// 修改用户信息
$("#updateauthorinfoform").submit(e => {
    e.preventDefault()
    var page = Number($('#authorpage').val())
    var formData = new FormData($("form")[0])
    $.ajax({
        url: '/editauthorinfo',
        type: 'post',
        data: formData,
        cache: false,
        contentType: false, //已经在表单的entype处声明了multipart/form-data
        processData: false, //data值是FormData对象，不需要对数据做处理
        success: (d) => {
            console.log("success");
            switch (d.code) {
                case 0:
                    swal.fire({ title: d.msg, type: "error" })
                    break;
                case 1:
                    swal.fire({ title: d.msg, type: "error" })
                    break;
                case 2:
                    swal.fire({ title: d.msg, type: "success" }).then(() => {
                        window.location.href = "/manageauthors?page= " + page
                    })
                    break;
            }
        },
        error: () => {
            swal.fire({ title: "服务器出错了", type: "error", confirmButtonText: '请重新登陆' }).then(() => {
                window.location.href = "/login"
            })
        }
    })
})